home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 132_01 / colorlib.a69 < prev    next >
Text File  |  1985-08-19  |  12KB  |  498 lines

  1.     #ASM
  2. ;+
  3. ;    6809    color computer support library
  4. ;-
  5. PIA0    EQU    0FF00H    ; Base address , PIA0
  6. PIA1    EQU    0FF20H    ; Base address , PIA1
  7. ADATA    EQU    0    ; A side PIA data
  8. ACNTRL    EQU    1    ; A side PIA control
  9. BDATA    EQU    2    ; B side Pia data
  10. BCNTRL    EQU    3    ; B side PIA control
  11. VDG    EQU    0FF22H    ; VDG control reg
  12. obj1:
  13.     FDB    obj2    ; forward pointer link
  14.     FDB    1    ; object number
  15.     FDB    2    ; max mumber of x bytes
  16.     FDB    6    ; max number of y bytes
  17.     FCB    0FFH,0,0FFH,0    ; object definition, object/mask
  18.     FCB    0c0H,03FH,003H,0fcH
  19.     FCB    0c0H,03fH,3,0fcH
  20.     FCB    0c0H,03fH,3,0fcH
  21.     FCB    0c0H,03fH,3,0fcH
  22.     FCB    0ffH,0,0ffH,0
  23. obj2:
  24.     FDB    obj3    ;forward pointer
  25.     FDB    2    ;object number
  26.     FDB    2    ; max x bytes
  27.     FDB    8    ;y bytes
  28.     FCB    1,0feH,0,0ffH
  29.     FCB    3,0fcH,080H,07fH
  30.     FCB    7,0f8H,0c0H,03fH
  31.     FCB    0aH,0f5H,0a0H,5fH
  32.     FCB    8,0f7H,020H,0dfH
  33.     FCB    4,0fbH,040H,0bfH
  34.     FCB    3,0fcH,080H,07fH
  35.     FCB    07fH,080H,0fcH,3
  36. obj3:        ; Small blob
  37.     FDB    0
  38.     FDB    3
  39.     FDB    1
  40.     FDB    7
  41.     FCB    01CH,0e3H
  42.     FCB    03eH,0c1H
  43.     fcb    07fH,080H,07fH,080H,07fH,080H
  44.     FCB    03eH,0c1H
  45.     FCB    01cH,0e3H
  46. ;+
  47. ;    Screen page display set up
  48. ;    This is a 'C' callable function which is passed the
  49. ;    desired address of the the display page.
  50. ;    NOTE: No 1/2 k boundary checking is performed !
  51. ;-
  52. SCNCTL    EQU    0FFC6H        ; Screen control port base addr.
  53. SETSCRN
  54.     LDD    2,S        ; Get the address
  55.     STD    SCRADR        ; Set up for next clock interrupt
  56.     RTS            ; Exit, request posted
  57. DOSET
  58.     LDX    #SCNCTL        ; Screen control port
  59.     LDA    #6        ; Number of bits to output
  60. SETSC1
  61.     TFR    A,B
  62.     ASL    3,S        ; Shift the page address
  63.     ROL    2,S
  64.     ROLB
  65.     STA    B,X
  66.     DECA
  67.     BPL    SETSC1
  68.     LDD    #0
  69.     STD    SCRADR
  70.     RTS
  71. ;+
  72. ;    Clock interrupt handler.
  73. ;-
  74. ;+
  75. ;    CLOCK EQUATES
  76. ;-
  77. CLKDAT    EQU    0FF02H
  78. CLKSTAT    EQU    0FF03H
  79. CLKJMP    EQU    010DH    ; Clock jump vector
  80. OLDCLK    EQU    894CH    ; Old extened color basic clock vector
  81. JOYRTX    EQU    346    ; Right joystick temp location
  82. JOYRTY    EQU    347    ; Right joystick y temp location
  83. ;
  84. CLOCK
  85.     LDA    CLKSTAT
  86.     BMI    CLOCK1
  87.     RTI        ; Spurious interrupt
  88. CLOCK1
  89.     LDA    CLKDAT    ; Clear clock interrupt
  90.     bsr    joyrx    ; right x joystick svce
  91.     stb    JOYRTX
  92.     bsr    joyry
  93.     stb    JOYRTY
  94.     LDD    SCRADR
  95.     BEQ    CLOCK2    ; Screen page change test
  96.     PSHS    D    ; Page address on stack
  97.     BSR    DOSET
  98.     PULS    D    ; clean off the stack
  99. CLOCK2
  100.     LDD    FLOP
  101.     beq    CLOCKX
  102.     SUBD    #1
  103.     STD    FLOP
  104. CLOCKX
  105.     RTI        ; Exit clock interrupt
  106. ;+
  107. ;    CLOCK data area
  108. ;-
  109. FLOP    RMB    2
  110. SCRADR    RMB    2    ; If non-zero, update the screen
  111. ;+
  112. ;    Putclk patches the clock interrupt vector to CLOCK
  113. ;-
  114. PUTCLK    
  115.     LDD    #CLOCK
  116.     STD    CLKJMP
  117.     RTS
  118. REMCLK        ; remove the clock. Put back the color clock svce
  119.     LDD    #OLDCLK
  120.     STD    CLKJMP
  121.     RTS
  122. IRQON        ; Interrupt on
  123.     ANDCC    #0EFH
  124.     RTS
  125. IRQOFF        ; Interrupt off
  126.     ORCC    #10H
  127.     RTS
  128. ;+
  129. ;    SPMOD4    Sets the SAM and VDG up for what is known as `pmode 4`
  130. ;    graphics mode : 256 by 192, green border, white pixels on a 
  131. ;    black background.
  132. ;-
  133. SPMOD4
  134.     clra
  135.     sta    0FFC5H
  136.     sta    0FFC3H    ; set up the SAM  control regs for mode 4
  137.     sta    0FFC0H
  138. ;+
  139. ;    Set the VDG control reg to match mode 4
  140. ;-
  141.     LDA    VDG
  142.     ORA    #0F0H
  143.     STA    VDG
  144.     RTS
  145. ;+
  146. ;    joystick    calls the read joystick routine. That's it.
  147. ;    Joystick values are left in the locations
  148. ;        Left    up/down    015Ha    right/left  015Hb
  149. ;        Right    up/down 015Hc    right/left  015Hd
  150. ;    no parameters returned.
  151. ;-
  152. joystick:
  153.     FCB    0adH,09fH
  154.     FDB    0a00aH        ; jsr [,a00a], joystick read
  155.     rts
  156. ;+
  157. ;    joyry    reads the right y joystick
  158. ;    Calls:    rysel
  159. ;    Inputs:    None
  160. ;    Outputs: value in B,  A is cleared
  161. ;    Regs used:    A - B
  162. ;-
  163. joyry:
  164.     pshs    x,y
  165.     bsr    rysel
  166.     bra    joysam        ; complete sample and exit 
  167. ;+
  168. ;    joyrx    reads only the left x joystick 
  169. ;    Calls:    rxsel
  170. ;    Inputs:    None
  171. ;    Outputs: returns value in B, A is cleared.
  172. ;    Regs used : A - B
  173. ;-
  174. joyrx:
  175.     pshs    x,y
  176.     bsr    rxsel    ; select right-x joystick
  177. joysam:
  178.     ldy    #PIA0    ; Y is set to PIA0 base address
  179.     ldx    #PIA1    ; X is set to DAC output PIA
  180. joyrx0:
  181.     ldb     #80H
  182.     stb    ,x    ; First comparator bit
  183.     lda    ,Y
  184.     bmi    jrx15    ; if too low
  185.     subb    #40H
  186.     bra    jrx20
  187. jrx15:
  188.     addb    #40H    ; add delta
  189. jrx20:
  190.     stb    ,x    ; Output second dac bit 
  191.     lda    ,y    ; Test comparator
  192.     bmi    jrx25    ; if too low
  193.     subb    #20H
  194.     bra    jrx30
  195. jrx25:
  196.     addb    #20H
  197. jrx30:
  198.     stb    ,x
  199.     lda    ,y
  200.     bmi    jrx35
  201.     subb    #10H
  202.     bra    jrx40
  203. jrx35:
  204.     addb    #10H
  205. jrx40:
  206.     stb    ,x
  207.     lda    ,y
  208.     bmi    jrx45
  209.     subb    #8
  210.     bra    jrx50
  211. jrx45:
  212.     addb    #8
  213. jrx50:
  214.     stb    ,X
  215.     lda    ,Y
  216.     bmi    jrx55
  217.     subb    #4
  218.     bra    jrx60
  219. jrx55:
  220.     addb    #4
  221. jrx60:
  222.     stb    ,x
  223.     lda    ,y
  224.     bmi    jrx65
  225.     subb    #2
  226.     bra    jrx70
  227. jrx65:
  228.     addb    #2
  229. jrx70:
  230.     lsrb
  231.     lsrb        ; Move down, only six bits of information
  232.     clra
  233.     puls    x,y
  234.     rts        ; exit, value in a-b
  235. ;+
  236. ;    rysel sets up for the right y joystick pot sample
  237. ;-
  238. rysel:
  239.     lda    (PIA0 + ACNTRL)
  240.     ora    #8
  241.     sta    (PIA0 + ACNTRL)
  242.     lda    (PIA0 + BCNTRL)
  243.     anda    #0F7H
  244.     sta    (PIA0 + BCNTRL)
  245.     rts
  246. ;+
  247. ;    rxsel sets up for the right x joystick pot
  248. ;-
  249. rxsel:
  250.     lda    (PIA0 + ACNTRL)
  251.     anda    #0F7H    ; Reset lsb of muxselect
  252.     sta    (PIA0 + ACNTRL)
  253.     lda    (PIA0 + BCNTRL)
  254.     anda    #0F7H    ; reset msb of mux
  255.     sta    (PIA0 + BCNTRL)
  256.     rts
  257. ;+
  258. ;    keyboard    reads the color computer keyboard.
  259. ;    returns    :    -1 if no character or
  260. ;            ascii character code
  261. ;    calls:        Internal keyboard scan at indirect a000
  262. ;-
  263. keyboard:
  264.     FCB    0adH,09fH
  265.     FDB    0a000H        ; jsr [,a000]
  266.     bne    keybd1        ; if a hit
  267.     FCB    0ccH
  268.     FDB    -1        ; ldd #-1
  269.     bra    keybdx
  270. keybd1:
  271.     FCB    01fH,089H    ; tfr a,b  move character to b
  272.     clra
  273. keybdx:    rts
  274. ;+
  275. ;    writeobj    is a graphics object writer. On entry, the
  276. ;    stack contains all paramters:
  277. ;        <starting screen address>
  278. ;        <number of bytes/line    >
  279. ;        <x position        >
  280. ;        <y position        >
  281. ;        < pointer to object def    >
  282. ;        < return address    >
  283. ;
  284. ;    All regs used.
  285. ;    Calls none.
  286. ;    Returns no parameters
  287. ;    Outputs object from definition table. Table format:
  288. ;        < Forward link pointer    >
  289. ;        < object number (word)    >
  290. ;        < x size in bytes    >
  291. ;        < y size in bytes    >
  292. ;        < first x byte        > bytes begin here
  293. ;        < corresponding mask byte>
  294. ;            .
  295. ;            .
  296. ;            .
  297. ;        < last xbyte on last y line>
  298. ;        <corresponding mask byte>
  299. ;    Note that all parameters are words (two bytes) execpt the
  300. ;    byte list definition of the object which is in byte pairs.
  301. ;    The first byte is the pixel information,
  302. ;    the second is a mask byte which shows which pixels are part
  303. ;    of the object. This allows 'holes' to be present in the
  304. ;    interior of an object, as an object is always defined by the
  305. ;    largest rectangle which can contain it.
  306. ;-
  307. writeobj:
  308. bufsiz    = 66
  309.     FCB    010H,0aeH,062H    ; Ldy 2,s , get object pointer
  310.     FCB    0a6H,067H    ; ld a 7,s  get xpos low byte
  311.     lsra
  312.     lsra            ; x/8 to get starting byte in line
  313.     lsra
  314.     FCB    034H,2    ;pshs a xbyte on stack
  315.     FCB    0a6H,068H    ;ld a 8,s get xpos again
  316.     FCB    084H,7    ;anda #7 bit offset
  317.     FCB    034H,2    ;pshs a shift count on stack
  318.     FCB    0a6H,025H    ;lda 5,y  low byte of xmax
  319.     FCB    034H,2    ;pshs a
  320.     FCB    0a6H,027H    ; ld a 7,y
  321.     FCB    034H,2    ;pshs a
  322.     clra
  323.     FCB    034H,2    ;pshs a  ymw init to zero on stack
  324.     FCB    031H,028H    ;leay 8,y  init y to head of bytelist
  325. ;+
  326. ;    Parameters are set up. The stack looks like
  327. ;      stack offset        parameter
  328. ;        F        < page addr     >
  329. ;        D        < nbytes    >
  330. ;        B        < xpos        >
  331. ;        9        < ypos        >
  332. ;        7        < obj def ptr    >
  333. ;        5        < return    >
  334. ;        4        < xbytes/line    >
  335. ;        3        < shift count    >
  336. ;        2        < xmax        >
  337. ;        1        < ymax        >
  338. ;        0        < ymax working    > - top of stack
  339. ;-
  340. ;+
  341. ;    output a line to the screen
  342. ;-
  343. line:
  344.     FCB    08eH
  345.     FDB    cline    ; ldx # cline, temp line buffer
  346.     FCB    0e6H,062H    ; ldb 2,s get xmax
  347. loop0:
  348.     FCB    0a6H,0a0H    ; lda ,y+ get color byte
  349.     FCB    0a7H,080H    ; sta ,x+ store in cline
  350.     FCB    0a6H,0a0H    ; lda ,y+ get mask byte
  351.     FCB    0a7H,089H    ; sta (bufsiz-1),x  store mask byte
  352.     FDB    bufsiz - 1
  353.     DECB
  354.     bne    loop0
  355.     FCB    06fH,080H    ;clr ,x+ blank for receiving shiftsk
  356.     FCB    06fH,089H    ;clr (bufsiz-1),x 
  357.     FDB    bufsiz - 1
  358.     FCB    063H,089H    ;com (bufsiz-1),x all ones for mask shifts
  359.     FDB    bufsiz - 1
  360.     FCB    0a6H,063H    ;ld a 3,s get shift count
  361.     beq    outline        ; if all is on byte boundaries
  362.     FCB    034H,2        ; pshs a  working copy of count
  363. shift:
  364.     FCB    0e6H,063H    ; ld b 3,s  xmax
  365.     INCB        ; one more byte for shifted bits
  366.     clra        ; clr carry
  367.     FCB    08eH
  368.     FDB    cline        ; ldx #cline
  369. clup:
  370.     FCB    066H,080H    ; ror ,x+ shift line to right
  371.     DECB
  372.     bne    clup
  373.     FCB    0e6H,063H    ; ldb 3,s  xmax
  374.     INCB
  375.     FCB    01aH,1        ; orcc 1, set carry for mask shifts
  376.     FCB    08eH
  377.     FDB    cline + bufsiz    ; ldx #cline+bufsiz